var e = {}, 
  url = "https://www.caihengyun.com/api",
  url = "http://localhost:7777/api", 

  urlMqtt =  "",
  webSocketUrl = "wss://www.caihengyun.com/apiws", 
  // webSocketUrl = "ws://localhost:7654/apiws", 
  // imgURL = 'https://img.yuedou.top/simple',
  imgURL = 'https://caihengyun.obs.cn-north-9.myhuaweicloud.com/simple',
  version = "v1.1.20",
  app = getApp();

e.httpPost = function (u, d, s, f) {
  var o = url + u;
  var user_id = getApp().getStorageSync('user_id');
  var access_token = getApp().getStorageSync('access_token')
  if (user_id == undefined || user_id == '' || user_id == null ){
    user_id = getApp().globalData.user_id;
  }
  var req_user_id = d["user_id"];
  if(!req_user_id){
    d["user_id"] = user_id;
  }

  // d["user_id"] =  590;
  // getApp().setStorageSync('user_id', 590);

  // d["user_id"] =  7;
  // getApp().setStorageSync('user_id', 7);

  d["user_id"] =  489;
  getApp().setStorageSync('user_id', 489);

  d["platform"] ="wxwork";
  wx.request({
    url: o,
    data: d,
    method: 'POST',
    header: { 
      "Content-Type": "application/json;charset=UTF-8",
      "user_id":user_id,
      "access_token":access_token,
      "platform":"wxwork"
    },
    success: function (t) {
      200 == t.statusCode ? s(t) : f(t);
    },fail: function (t) { f(t); }
  });
}

e.httpPostMqtt = function (u,d, s, f) {
  var o = urlMqtt + u;
  var user_id = getApp().getStorageSync('user_id');
  var access_token = getApp().getStorageSync('access_token')
  if (user_id == undefined || user_id == '' || user_id == null ){
    user_id = getApp().globalData.user_id;
  }
  var req_user_id = d["user_id"];
  if(!req_user_id){
    d["user_id"] = user_id;
  }

  d["platform"] = "wxwork";
  
  wx.request({
    url: o,
    data: d,
    method: 'POST',
    header: { 
      "Content-Type": "application/json;charset=UTF-8",
      "user_id":user_id,
      "access_token":access_token,
      "platform":"wxwork"
    },
    success: function (t) {
      200 == t.statusCode ? s(t) : f(t);
    },fail: function (t) { f(t); }
  });
}

e.getPlatformUrl=function(){
  return url;
}
e.getWebSokectUrl=function(){
  return webSocketUrl;
}
e.getImgUrl=function(){
  return imgURL;
}

e.getVersion=function(){
  return version;
}
module.exports = e;